
<div class="layui-card layadmin-header">
  <div class="layui-breadcrumb" lay-filter="breadcrumb">
    <a lay-href="">主页</a>
    <a>应用管理</a>
    <a><cite>渠道列表</cite></a>
  </div>
</div>

<div class="layui-fluid">
  <div class="layui-card">
    <div class="layui-tab layui-tab-brief">
      <ul class="layui-tab-title">
        <li class="layui-this">支付渠道列表</li>
      </ul>
      <div class="layui-tab-content">
        <div class="layui-tab-item layui-show">
          <div class="layui-row">
            <div class="layui-form" style="float:right;">
              <div class="layui-form-item" style="margin:0;">
                <label class="layui-form-label">应用ID</label>
                <div class="layui-input-inline">
                  <input type="text" name="appId" id="appId" placeholder="应用ID" autocomplete="off" class="layui-input">
                </div>
                <label class="layui-form-label">商户ID</label>
                <div class="layui-input-inline">
                  <input type="text" name="mchId" id="mchId" placeholder="商户ID" autocomplete="off" class="layui-input">
                </div>
                <button id="search" class="layui-btn" data-type="reload">搜索</button>
              </div>
            </div>
          </div>
          <div class="layui-row">
            <div class="layuiAdmin-btns" style="margin-bottom: 10px;"></div>
          </div>
          <table id="Pay_Mgr_Channel_dataAll" lay-filter="Pay_Mgr_Channel_dataAll"></table>
        </div>

      </div>
    </div>
  </div>
</div>

<script type="text/html" id="payBar">
  <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="detail">查看</a>
  <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
</script>

<script>
  layui.use(['admin', 'table', 'util','form'], function(){
    var $ = layui.$
            ,admin = layui.admin
            ,table = layui.table
            ,element = layui.element
        ,view =layui.view
        ,layer =layui.layer
            ,form = layui.form;

    element.render('breadcrumb', 'breadcrumb');


    var tplStatus = function(d){
      if(d.state == 1) {
        return "<span class='layui-btn layui-btn-xs'>启用</span>";
      }
      return "<span class='layui-btn layui-btn-xs layui-btn-disabled'>停止</span>";
    };

    var channelTypeStatus = function(d){
      if(d.channelType == "alipay") {
        return "支付宝";
      }else if(d.channelType == "wxpay") {
        return "微信支付"
      }else if(d.channelType == "qpay") {
        return "qq支付"
      }else if(d.channelType == "upacp") {
        return "银联支付";
      }else if(d.channelType == "applepay") {
        return "苹果支付";
      }else if(d.channelType == "bfb") {
        return "百付宝支付"
      }else if(d.channelType == "jdpay") {
        return "京东支付";
      }else if(d.channelType == "kqpay") {
        return "快钱支付";
      }else {
        return "";
      }
    };

    //商户列表
    table.render({
      elem: '#Pay_Mgr_Channel_dataAll'
      ,url: layui.setter.baseUrl + '/mch_channel/list' //列表接口
      // ,where: {appId:curAppId}
      ,where: {
          access_token: layui.data(layui.setter.tableName).access_token
      }
      ,id: 'tableReload'
      ,page: true
      ,cols: [[
        {type: 'checkbox', fixed: 'left'}
        ,{field:'channelId', title: '支付渠道ID'}
        ,{field:'channelType',  title: '支付产品',templet: channelTypeStatus}
        ,{field:'scene', title: '应用场景',templet: '<div>{{d.scene == 1?"移动APP":(d.scene == 2)?"移动网页":(d.scene == 3)?"PC网页":(d.scene == 4)?"微信公众平台":(d.scene == 5)?"手机扫码":""}}</div>'  }
        ,{field: 'appId', title: '应用ID'}
        ,{field: 'mchId', title: '商户ID'}
        ,{field: 'state', title: '状态', templet: tplStatus}
        ,{field: 'createTime', title: '创建时间', width: 200, templet: '<div>{{ layui.util.toDateString(d.createTime, "yyyy-MM-dd HH:mm:ss") }}</div>'}
        ,{field: 'edit', title: '操作', width: 320, toolbar: '#payBar' }
      ]]
      ,skin: 'line'
    });

    //监听工具条
    table.on('tool(Pay_Mgr_Channel_dataAll)', function(obj){
      var data = obj.data;
      if(obj.event === 'detail'){
          var curAppId =data.id;
          location.href = layui.setter.baseLocal + "app/mch_channel/channel_view/id=" + curAppId;
      } else if(obj.event === 'edit'){

          location.hash = "/app/mch_channel/channel_edit/id=" + data.id + "/channelId=" + data.channelId + "/channelType=" + data.channelType  ;
      }

    });

    // 搜索
    var $ = layui.$, active = {
      reload: function(){
        var mchId = $('#mchId').val();
        var appId = $("#appId").val();
        //执行重载
        table.reload('tableReload', {
          page: {
            curr: 1 //重新从第 1 页开始
          }
          ,where: {

            mchId: mchId,
            appId : appId
          }
        });
      }
    };
    $('#search').on('click', function() {
      var type = $(this).data('type');
      active[type] ? active[type].call(this) : '';
    });

    // 渲染表单
    form.render();
  });
</script>